package com.gareve.twoSides.models;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Vector2;
import com.gareve.twoSides.GameConstants;

public class Obstacle extends LivingGameObject{
	public static final float WIDTH = 2f;
	public static final float HEIGHT = 2f;
	
	private static final Color CRASH_COLOR = new Color(1f, 0f, 0f, 1f);
	private static final Color NORMAL_COLOR = new Color(0f, 1f, 0f, 1f);

	private Vector2 speed;
	public boolean crashed;

	public Obstacle(float x, float y,Vector2 speed) {
		super(x, y, WIDTH,HEIGHT,speed);
		this.speed = speed;
		crashed = false;
	}

	public void move(float delta){
		shape.x += speed.x * delta;
		shape.y += speed.y * delta;
	}
	
	public boolean isAlive(){
		return isAlive 
				&& shape.x + shape.width >= 0f && shape.x <= GameConstants.SCREEN_WIDTH
				&& shape.y + shape.height >= 0f && shape.y <= GameConstants.SCREEN_HEIGHT;
	}

	public void render(ShapeRenderer shapeRenderer) {
		shapeRenderer.begin(ShapeType.Rectangle);
			shapeRenderer.setColor(crashed?CRASH_COLOR:NORMAL_COLOR);
			shapeRenderer.rect(shape.x, shape.y, shape.width, shape.height);
		shapeRenderer.end();
	}
	
	public boolean collide(PlayerObject player){
		return Intersector.intersectRectangles(shape, player.shape);
	}
}
